import {defineConfig} from 'vite'
import path from 'path'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
    base: './',
    plugins: [
        vue(),
        // Element自动导入
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
    ],
    resolve: {
        alias: {
            '@': path.resolve('./src'),
        },
    },
    css: {
        preprocessorOptions: {
            scss: {
                javascriptEnabled: true,
                additionalData:
                    '@import "./src/styles/variable.scss";',
            },
        },
    },
    build: {
        outDir: 'dist',
        minify: false,
        // 禁用 gzip 压缩大小报告，可略微减少打包时间
        reportCompressedSize: false,
        // 规定触发警告的 chunk 大小
        chunkSizeWarningLimit: 2000,
        rollupOptions: {
            output: {
                // 配置rollup输出选项
                // Static resource classification and packaging//静态资源分类打包
                chunkFileNames: `js/[name]-[hash].js`, //代码块文件名
                entryFileNames: `js/[name]-[hash].js`, //入口文件名
                assetFileNames: '[ext]/[name]-[hash].[ext]', // 资源文件名

                manualChunks(id) {
                    if (id.includes('node_modules')) {
                        return id
                            .toString()
                            .split('node_modules/')[1]
                            .split('/')[0]
                            .toString()
                    }
                },
            },
        },
    },
})
